#include <stdio.h>

class base
{
public:
	base() {
		printf("base()\n");
	}

	~base() {
		printf("~base()\n");
	}

	virtual void calltest() {
		printf("base::calltest()\n");
		test();		//基类调用test
	}

	virtual void test() {
		printf("base::test()\n");
	}
};

class sub : public base
{
public:
	sub() {
		printf("sub()\n");
	}

	~sub() {
		printf("~sub()\n");
	}

	virtual void test() {
		printf("sub::test()\n");
	}
};

int main()
{
	sub sub;
	/*
	调用基类的calltest, calltest传了一个隐含的this指针,该指针为sub类型,
	在calltest中调用test()时相当于this->test(), this为sub类型, 由多态可知,
	调用sub类的test()函数
	*/
	sub.calltest();
}